package huy.mmt.gamelathinh.dialog;

import huy.mmt.gamelathinh.Main;
import huy.mmt.gamelathinh.MySharedPreferences;
import huy.mmt.gamelathinh.Play;
import huy.mmt.gamelathinh.R;
import huy.mmt.gamelathinh.Setting;
import huy.mmt.gamelathinh.util.Util;
import huy.mmt.gamelathinh.util.UtilDialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;

/**
 * Hiá»‡n thá»‹ khi ngÆ°á»�i dÃ¹ng chá»�n setting. NgÆ°á»�i dÃ¹ng cÃ³ thá»ƒ táº¯t báº­t nháº¡c ná»�n cÅ©ng
 * nhÆ° Ã¢m thanh trong game
 * 
 * @author VAN GIOI
 * 
 */
public class DialogSetting extends Dialog implements
		android.view.View.OnClickListener {

	Button yes;
	Activity activity;
	CheckBox check_music, check_sound;

	MySharedPreferences mySharedPreferences;

	public DialogSetting(Context context) {
		super(context);
		UtilDialog.iniDialog(this);
		activity = (Activity) context;
		setContentView(R.layout.dialog_setting);

		mySharedPreferences = new MySharedPreferences(context);
		mySharedPreferences.getIsMusic();
		mySharedPreferences.getIsSound();

		// resize dialog
		LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayout_all);
		Util.resizeDialog(linearLayout);

		yes = (Button) findViewById(R.id.yes);
		yes.setOnClickListener(this);

		check_music = (CheckBox) findViewById(R.id.check_mussic);
		check_music.setOnClickListener(this);
		check_music.setChecked(Setting.isMusic);

		check_sound = (CheckBox) findViewById(R.id.check_sound);
		check_sound.setOnClickListener(this);
		check_sound.setChecked(Setting.isSound);
	}

	@Override
	public void onClick(View v) {

		Main.click.start();

		switch (v.getId()) {
		case R.id.yes:
			this.dismiss();
			break;
		case R.id.check_mussic:
			Setting.isMusic = check_music.isChecked();

			if (Setting.isMusic) {

				Play.ms_bg.start();
			

			} else {
				
				Play.ms_bg.pause();
				if (Setting.isMusic) {
					Setting.isMusic = true;
				}
				else {
					Setting.isMusic=false;
				}

			}
			mySharedPreferences.updateIsMusic(Setting.isMusic);
			break;
		case R.id.check_sound:
			Setting.isSound = check_sound.isChecked();
			mySharedPreferences.updateIsSound(Setting.isSound);
			break;

		default:
			break;
		}

	}

}